package com.zhiyou100.springbootweather.config;

import com.zhiyou100.springbootweather.job.WeatherJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建执行时间对象
 */
@Configuration
public class QuartzConfig {
    /*创建JobDetail对象*/
    @Bean
    public JobDetail redisJobDetail() {

        return JobBuilder.newJob(WeatherJob.class)
                .withIdentity("weatherJob")
                .storeDurably().build();
    }
    /*创建Trigger对象*/
    @Bean
    public Trigger reidsTrigger(){
        //设置定时策略
        SimpleScheduleBuilder scheduleBuilder= SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInMinutes(30)//分钟
                .repeatForever();//永久调用
        //创建Trigger对象
        return TriggerBuilder.newTrigger()
                //forJob 是上方定义的JobDetail对象
                .forJob(redisJobDetail()).withIdentity("weatherTrigger")
                .withSchedule(scheduleBuilder).build();


    }
}
